<?php
Class PTdomainModel extends CI_Model {
	
function _construct()
	{
        parent::_construct();
        //$this->load->helper(array('form', 'url'));
        //$this->load->library('form_validation');
        $this->load->library('session');
        $this->load->library('security');
        $this->load->library('tank_auth');
        $this->load->model('penjelasan_domain/PTdomainModel');
        $this->load->database();
    }
    
    
    function select_domain()
    {
    	$data = $this->db->query("select penjelasan_domain from penjelasan_domain");
        return $data;
    }
    
	function insertPTDomain($usiaid,$userid,$domainke,$nilaidomain,$leveldomain)
	{
//		ptdomainid,userid,usiaid,domainke,nilaidomain,leveldomain
		$data = array(
			'USIAPERUBAHANID' => $usiaid,
			'USERID' => $userid,
			'DOMAINKE' => $domainke,
			'NILAIDOMAIN' => $nilaidomain,
			'LEVELDOMAIN' => $leveldomain
			);
		$this->db->insert('ptdomain', $data);
			
	}
	
	function getPTDomain($userid, $usiaid) {
		$sql = "select PTDOMAINID, DOMAINKE, NILAIDOMAIN, LEVELDOMAIN from ptdomain where USERID = $userid and 
				USIAPERUBAHANID = $usiaid order by DOMAINKE ASC";
		$data = $this->db->query($sql);
		return $data;
	}
	
//	function insertPTDomain($domainid,$usiaid,$userid,$domainke,$nilaidomain,$leveldomain)
//	{
////		ptdomainid,userid,usiaid,domainke,nilaidomain,leveldomain
//		$data = array(
//			'PTDOMAINID' => $domainid,
//			'USIAPERUBAHANID' => $usiaid,
//			'USERID' => $userid,
//			'DOMAINKE' => $domainke,
//			'NILAIDOMAIN' => $nilaidomain,
//			'LEVELDOMAIN' => $leveldomain
//			);
//		$this->db->insert('ptdomain', $data);
//			
//	}
	
	
	function getLastDomainid()
	{
		$sql = "SELECT MAX(ptdomainid) AS maxid FROM ptdomain";
		$hasil = $this->db->query($sql);
		$max = $hasil->row();
		return $max->maxid;
	}
	function getSkorDomain($userid, $usiaid)
	{
		$this->db->select('nilaidomain');
		$this->db->from('ptdomain');
		$this->db->where('userid',$userid);
		$this->db->where('usiaperubahanid',$usiaid);
		$this->db->order_by('domainke','asc');
		$data = $this->db->get();
		return $data;
		
	}
}
?>